package common.ui.controls
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	

	[Event(name="close", type="flash.events.Event")]
	public class SimpleWindow extends Sprite
	{
		protected var _dis:Sprite;
		protected var _closeButton:DisplayObject;
		
		public function SimpleWindow()
		{
			this.addEventListener(MouseEvent.CLICK,switchToTop);
		}
		
		public function setCloseButton(closeButton:DisplayObject = null):void
		{
			if(closeButton == null)
			{
				closeButton = _dis.getChildByName("close_btn");
			}
			closeButton.addEventListener(MouseEvent.CLICK,close);
			_closeButton = closeButton;
		}
		
		
		public function close(event:MouseEvent=null):void
		{
			if(this.parent != null)
			{
				this.parent.removeChild(this);
				this.dispatchEvent(new Event("close"));
			}
		}
		public function switchToTop(event:MouseEvent=null):void
		{
			if(this.parent != null)
			{
				this.parent.setChildIndex(this,this.parent.numChildren-1);
			}
		}
	}
}